package io.renren.modules.wiki.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.renren.modules.wiki.dto.ArticleEntityDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.wiki.dao.ArticleDao;
import io.renren.modules.wiki.entity.ArticleEntity;
import io.renren.modules.wiki.service.ArticleService;


@Service("articleService")
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, ArticleEntity> implements ArticleService {
    @Autowired
    ArticleDao articleDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ArticleEntity> page = this.page(
                new Query<ArticleEntity>().getPage(params),
                new QueryWrapper<ArticleEntity>()
        );
        return new PageUtils(page);
    }
    public PageInfo<ArticleEntityDto> queryPage(ArticleEntityDto articleEntityDto) {
        return findByOptionsWithPage(articleEntityDto.getPageNum(),articleEntityDto.getPageSize(),articleEntityDto);
    }

    public PageInfo<ArticleEntityDto> findByOptionsWithPage(int page, int pageSize, ArticleEntityDto articleEntityDto) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(articleDao.findByOptions(articleEntityDto));
    }
}